﻿using System;

namespace GPToolkit.Helpers
{
	public static class DateTimeHelper
	{
		/// <summary>
		/// Calculate the age
		/// </summary>
		/// <param name="birthDate">The birth date</param>
		/// <returns>The age</returns>
		public static int CalculateAge(DateTime birthDate) {
			DateTime now = DateTime.Today;

			// get the difference in years
			int age = now.Year - birthDate.Year;

			// subtract another year if we're before the birth day in the current year
			if (now.Month < birthDate.Month || (now.Month == birthDate.Month && now.Day < birthDate.Day)) {
				--age;
			}

			return age;
		}
	}
}
